<template>
  <div class="base-container">
    <!--    <t-row>-->
    <div style="position: fixed; width: 20%; height: 100%; overflow: scroll; padding-bottom: 100px">
      <t-loading size="small" :loading="dataLoading" showOverlay>
        <div>
          <t-tree
            line
            ref="tree"
            :keys="{ value: 'id', label: 'name' }"
            :actived="actived"
            expand-all
            :data="TreeReviewTeamData"
            @active="onTreeActive"
            activable
            hover
            transition
          >
            <template #label="{ node }">
              {{ node.data.name
              }}<span v-if="!['1'].includes(node.data.reviewMenuType) && node.data.projectCount"
                >(<span style="color: #176eff">{{ node.data.projectCount }}</span
                >)</span
              >
            </template>
            <template #operations="{ node }">
              <t-button
                v-if="['1'].includes(node.data.reviewMenuType)"
                size="small"
                variant="text"
                @click="
                  dialog.header = '添加组';
                  dialog.objId = 0;
                  dialog.parentId = node.data.id;
                  dialog.open_add_edit = true;
                "
              >
                <t-icon name="add" slot="icon" />
              </t-button>
              <t-button
                v-if="node.data.name !== '评审分组体系'"
                size="small"
                variant="text"
                @click="
                  dialog.header = '编辑组';
                  dialog.objId = node.data.id;
                  dialog.parentId = 0;
                  dialog.open_add_edit = true;
                "
              >
                <t-icon name="edit-1" slot="icon" />
              </t-button>
              <t-popconfirm
                v-if="node.data.name !== '评审分组体系'"
                @confirm="removeNode(node)"
                theme="warning"
                content="确认删除分组吗"
              >
                <t-button size="small" variant="text">
                  <t-icon name="delete" slot="icon" />
                </t-button>
              </t-popconfirm>
            </template>
          </t-tree>
        </div>
      </t-loading>
    </div>

    <!-- 右侧内容 -->
    <div style="margin-left: 24%; height: 100%">
      <t-loading size="small" :loading="baseLoading" showOverlay>
        <t-card>
          <div>
            <template>
              <div :style="{ width: '200px' }">
                <t-divider>基本信息</t-divider>
              </div>
            </template>
            <t-form labelWidth="150px" :data="formData" ref="form" :colon="true">
              <t-row style="row-gap: 10px">
                <t-col :span="6">
                  <t-form-item label="分组名" name="name">
                    {{ formData.name }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="评审业务类型" name="reviewType">
                    {{ formData.reviewType | filterByDict(dict.type.kjsf_review_type) }}
                  </t-form-item>
                </t-col>
                <t-col v-if="['1'].includes(formData.reviewType)" :span="6">
                  <t-form-item label="指标体系" name="indexId">
                    {{ formData.indexId | filterByDict(dataOptions) }}
                    <t-button
                      v-if="formData.indexId"
                      @click="
                        dialog.header = '评审指标体系详情';
                        dialog.objId = formData.indexId;
                        dialog.open_review_standard = true;
                      "
                      variant="text"
                      class="t-button-link"
                    >
                      <t-icon name="info-circle" slot="icon" />
                      详情
                    </t-button>
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="专家评审开始时间" name="startReviewDate">
                    {{ formData.startReviewDate }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="专家评审截止时间" name="endReviewDate">
                    {{ formData.endReviewDate }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="评审会议时间" name="reviewMeetingDate">
                    {{ formData.reviewMeetingDate }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="分组说明" name="note">
                    {{ formData.note }}
                    <!--                      <t-textarea style="width: 240px" disabled v-model="formData.note"></t-textarea>-->
                  </t-form-item>
                </t-col>
              </t-row>
            </t-form>
            <t-divider></t-divider>
            <!-- 专家 -->
            <t-row>
              <t-col :xs="2" :sm="4" :md="6" :lg="8" :xl="9">
                <div class="btn-group-inline">
                  <t-button
                    :disabled="!formData.id"
                    @click="handleExport(`/kjsf/excel/reviewTeamInfo`, formData.id, `${formData.name}-评审组信息`)"
                  >
                    <template #icon>
                      <DownloadIcon />
                    </template>
                    导出评审信息
                  </t-button>
                  <t-button
                    :disabled="!formData.id"
                    @click="handleExport(`/kjsf/excel/exportPayInfo`, formData.id, `${formData.name}-评审组付款信息`)"
                  >
                    <template #icon>
                      <DownloadIcon />
                    </template>
                    导出账户信息
                  </t-button>
                  <t-button :disabled="!formData.id" @click="handleExportPDF(formData.id)">
                    <template #icon>
                      <DownloadIcon />
                    </template>
                    导出账户信息(签名)
                  </t-button>
                  <!--                    <t-button :disabled="!formData.id" @click="handleGroupSms(formData.id)">
                    <template #icon>
                      <MailIcon />
                    </template>
                    专家短信邀请</t-button>-->
                </div>
              </t-col>
              <t-col :xs="10" :sm="8" :md="6" :lg="4" :xl="3">
                <div style="justify-content: flex-end" class="btn-group-inline">
                  <t-button :disabled="!formData.id" @click="selectProject"
                    ><template #icon>
                      <ListIcon /> </template
                    >选择项目</t-button
                  >
                  <t-tooltip v-if="projectList.length <= 0" content="请先选择项目">
                    <t-button :disabled="!formData.id">
                      <template #icon>
                        <AssignmentUserIcon /> </template
                      >抽取专家
                    </t-button>
                  </t-tooltip>
                  <t-button :disabled="!formData.id" v-else @click="selectExpert"
                    ><template #icon>
                      <AssignmentUserIcon /> </template
                    >抽取专家</t-button
                  >
                </div>
              </t-col>
            </t-row>
            <t-divider></t-divider>
            <t-tabs :disabled="!formData.id" :defaultValue="formData.id ? 1 : 0">
              <t-tab-panel :value="1" label="本组评审项目">
                <t-row>
                  <t-table
                    rowKey="id"
                    :data="projectList"
                    :columns="['1'].includes(formData.reviewType) ? projectColumns : projectColumns2"
                    :bordered="true"
                    :hover="true"
                  >
                    <template #[`project.projectName`]="{ row }">
                      <t-link @click="openProjectDetail(row)" hover="color" theme="primary"
                        >{{ row.project.projectName }}
                      </t-link>
                    </template>
                    <template #[`project.adviceFunding`]="{ row }"> {{ row.project.adviceFunding }}万元 </template>
                    <template #[`project.projectType`]="{ row }">
                      {{ row.project?.projectType | filterByDict(dict.type.project_type) }}
                    </template>
                    <template #op="{ row }">
                      <t-tooltip v-if="expertList.length <= 0" content="请先抽取专家">
                        <t-button size="small" variant="text" class="t-button-link">
                          <t-icon name="root-list" slot="icon" />
                          专家评审详情
                        </t-button>
                      </t-tooltip>
                      <t-button v-else @click="openReviewDetail(row)" size="small" variant="text" class="t-button-link">
                        <t-icon name="root-list" slot="icon" />
                        专家评审详情
                      </t-button>
                      <!--                  <t-button v-if="formData.reviewType !== '1'" @click="getTeamExpertLeaderFile(row)" size="small"-->
                      <!--                            variant="text" class="t-button-link">-->
                      <!--                    <t-icon name="info-circle" slot="icon"/>-->
                      <!--                    专家组长评审意见表-->
                      <!--                  </t-button>-->
                      <t-button
                        @click="
                          dialog.objId = row.id;
                          dialog.projectName = row.project.projectName;
                          dialog.projectId = row.project.id;
                          dialog.open_project_approval = true;
                        "
                        size="small"
                        variant="text"
                        class="t-button-link"
                      >
                        <t-icon name="check-circle" slot="icon" />
                        评审判定
                      </t-button>
                      <!--                    <t-button @click="dialog.header=row.project.projectName;dialog.objId=row.project.id;dialog.editOpen=false;dialog.open_project_detail=true" size="small" variant="text" class="t-button-link">-->
                      <!--                      <t-icon name="info-circle" slot="icon"/>-->
                      <!--                      项目详情-->
                      <!--                    </t-button>-->
                      <!--                  <t-button v-if="formData.reviewType === '2'"-->
                      <!--                            @click="dialog.header=row.project.projectName;dialog.objId=row.project.id;dialog.editOpen=false;dialog.open_outline_detail=true"-->
                      <!--                            size="small" variant="text" class="t-button-link">-->
                      <!--                    <t-icon name="info-circle" slot="icon"/>-->
                      <!--                    大纲详情-->
                      <!--                  </t-button>-->
                      <!--                  <t-button v-if="formData.reviewType === '3'"-->
                      <!--                            @click="dialog.header=row.project.projectName;dialog.objId=row.project.id;dialog.editOpen=false;dialog.open_acceptance_detail=true"-->
                      <!--                            size="small" variant="text" class="t-button-link">-->
                      <!--                    <t-icon name="info-circle" slot="icon"/>-->
                      <!--                    验收详情-->
                      <!--                  </t-button>-->
                      <t-button
                        theme="danger"
                        @click="teamProjectDel(row.id)"
                        size="small"
                        variant="text"
                        class="t-button-link"
                      >
                        <t-icon name="delete" slot="icon" />
                        删除
                      </t-button>
                    </template>
                    <template #projectStatus="{ row }">
                      <t-tag theme="success" variant="light" v-if="row.projectStatus === '1'"> 是 </t-tag>
                      <t-tag theme="danger" variant="light" v-else-if="row.projectStatus === '0'"> 否 </t-tag>
                      <t-tag theme="warning" variant="light" v-else-if="row.projectStatus === '2'"> 需要复议 </t-tag>
                      <t-tag theme="warning" variant="light" v-else> 未提交 </t-tag>
                    </template>
                  </t-table>
                </t-row>
              </t-tab-panel>
              <t-tab-panel :value="2" label="本组评审专家">
                <t-row>
                  <t-table rowKey="id" :data="expertList" :columns="expertColumns" :bordered="true" :hover="true">
                    <template #[`experts.sysUser.nickName`]="{ row }">
                      <t-badge
                        v-if="row.teamLeader === '1' && !['1'].includes(formData.reviewType)"
                        count="组长"
                        :offset="[-10, -6]"
                      >
                        <t-link
                          style="margin-right: 0"
                          @click="
                            dialog.objId = row.experts.id;
                            dialog.idCard = row.experts.sysUser.idCard;
                            dialog.header = row.experts.sysUser.nickName;
                            dialog.open_expert_detail = true;
                          "
                          hover="color"
                          theme="primary"
                        >
                          {{ row.experts.sysUser.nickName
                          }}<span v-if="row.experts.isInviteExpert === '1'" style="color: red">(邀)</span>
                        </t-link>
                      </t-badge>
                      <template v-else>
                        <t-link
                          @click="
                            dialog.objId = row.experts.id;
                            dialog.idCard = row.experts.sysUser.idCard;
                            dialog.header = row.experts.sysUser.nickName;
                            dialog.open_expert_detail = true;
                          "
                          hover="color"
                          theme="primary"
                        >
                          {{ row.experts.sysUser.nickName
                          }}<span v-if="row.experts.isInviteExpert === '1'" style="color: red">(邀)</span>
                        </t-link>
                      </template>
                    </template>
                    <template #[`experts.sysUser.phonenumber`]="{ row }">
                      <t-badge v-if="row.experts.isJx !== '1'" count="省外" :offset="[-10, -6]">
                        {{ row.experts.sysUser.phonenumber }}
                      </t-badge>
                      <div v-else>
                        {{ row.experts.sysUser.phonenumber }}
                      </div>
                    </template>
                    <template #[`experts.sysUser.duty`]="{ row }">
                      <div v-if="['99999', ''].includes(row.experts.sysUser?.profTit)">
                        {{ row.experts.sysUser?.duty }}
                      </div>
                      <div v-else>
                        <t-tooltip :content="getDuty(row.experts.sysUser?.duty, row.experts.sysUser?.profTit)">
                          <p class="duty-text">
                            {{ row.experts.sysUser?.duty }}/{{
                              row.experts.sysUser?.profTit | filterByDict(dict.type.prof_tit)
                            }}
                          </p>
                        </t-tooltip>
                      </div>
                    </template>
                    <template #[`experts.sysUser.education`]="{ row }">
                      {{ row.experts.sysUser?.education | filterByDict(dict.type.education) }}/{{
                        row.experts.sysUser?.degree | filterByDict(dict.type.degree)
                      }}
                    </template>
                    <!--                    <template #[`experts.sysUser.degree`]="{ row }">-->
                    <!--                      {{ row.experts.sysUser?.degree | filterByDict(dict.type.degree) }}-->
                    <!--                    </template>-->
                    <template #[`sendMsg`]="{ row }">
                      <t-tag v-if="row.sendMsg === '1'" theme="success" variant="light">发送成功</t-tag>
                      <t-tag v-else-if="row.sendMsg === '0'" theme="danger" variant="light">发送失败</t-tag>
                      <t-tag v-else theme="warning" variant="light">未发送</t-tag>
                      /
                      <t-tag v-if="row.joinType === '1'" theme="success" variant="light">参加</t-tag>
                      <t-tag v-else-if="row.joinType === '0'" theme="danger" variant="light">不参加</t-tag>
                      <t-tag v-else theme="warning" variant="light">未回复</t-tag>
                    </template>
                    <template #op="{ row }">
                      <!--                    <t-tooltip trigger="click" placement="top" theme="light">-->
                      <!--                      <div slot="content">-->
                      <!--                        <div v-for="(item,index) in temList" :key="index">-->
                      <!--                          <t-button @click="handleGroupSms(formData.id,item.id)" variant="text" class="t-button-link">-->
                      <!--                            <t-icon name="cloud" slot="icon"/>-->
                      <!--                            {{ item.type | filterByDict(dict.type.msg_template_type) }}-->
                      <!--                          </t-button>-->
                      <!--                        </div>-->
                      <!--                      </div>-->
                      <!--                      <t-button size="small" variant="text"-->
                      <!--                                class="t-button-link">-->
                      <!--                        <t-icon name="cloud" slot="icon"/>-->
                      <!--                        短信邀请-->
                      <!--                      </t-button>-->
                      <!--                    </t-tooltip>-->
                      <t-button
                        v-if="row.experts.isJx == '1'"
                        @click="
                          dialog.formData = formData;
                          dialog.objId = row.id;
                          dialog.sendType = 2;
                          dialog.nickName = row.experts.sysUser.nickName;
                          dialog.open_sms_template = true;
                        "
                        size="small"
                        variant="text"
                        class="t-button-link"
                      >
                        <t-icon name="cloud" slot="icon" />
                        短信邀请
                      </t-button>
                      <t-button
                        v-if="formData.reviewType !== '1'"
                        @click="setTeamExpertLeader(row)"
                        size="small"
                        variant="text"
                        class="t-button-link"
                      >
                        <t-icon name="edit-1" slot="icon" />
                        设为组长
                      </t-button>
                      <t-button
                        theme="danger"
                        @click="teamExpertDel(row.id)"
                        size="small"
                        variant="text"
                        class="t-button-link"
                      >
                        <t-icon name="delete" slot="icon" />
                        删除
                      </t-button>
                    </template>
                  </t-table>
                </t-row>
              </t-tab-panel>
            </t-tabs>
            <t-alert v-if="!formData.id" message="请选择评审组" />
          </div>
        </t-card>
      </t-loading>
    </div>

    <!--    </t-row>-->
    <!-- 添加分组  编辑分组 -->
    <add-edit-group
      @reload="getListReviewTeam()"
      @changeActived="changeActived"
      :header="dialog.header"
      :parentId="dialog.parentId"
      :objId="dialog.objId"
      :visible.sync="dialog.open_add_edit"
      v-if="dialog.open_add_edit"
    >
    </add-edit-group>
    <select-project
      header="选择项目"
      @reload="teamProjectGet"
      :formData="formData"
      :visible.sync="dialog.open_select_project"
      v-if="dialog.open_select_project"
    >
    </select-project>
    <select-expert
      header="抽取专家"
      @reload="teamExpertGet"
      :formData="formData"
      :visible.sync="dialog.open_select_expert"
      v-if="dialog.open_select_expert"
    ></select-expert>
    <expert-review-list
      :rowId="dialog.rowId"
      :expert-leader="dialog.expertLeader"
      :teamId="dialog.teamId"
      :objId="dialog.objId"
      :reviewType="formData.reviewType"
      :projectName="dialog.projectName"
      :visible.sync="dialog.open_review_list"
      v-if="dialog.open_review_list"
    ></expert-review-list>

    <project-approval
      @reload="teamProjectGet"
      :header="dialog.header"
      :projectName="dialog.projectName"
      :reviewType="formData.reviewType"
      :projectId="dialog.projectId"
      :objId="dialog.objId"
      :visible.sync="dialog.open_project_approval"
      v-if="dialog.open_project_approval"
    ></project-approval>

    <add-edit-review-standard
      :header="dialog.header"
      :editOpen="false"
      :objId="dialog.objId"
      :visible.sync="dialog.open_review_standard"
      v-if="dialog.open_review_standard"
    ></add-edit-review-standard>

    <expert-sms-template
      @reload="teamExpertGet"
      :nick-name="dialog.nickName"
      :form-data="dialog.formData"
      :send-type="dialog.sendType"
      :obj-id="dialog.objId"
      :visible.sync="dialog.open_sms_template"
      v-if="dialog.open_sms_template"
    ></expert-sms-template>
    <expert-detail-dialog
      :header="dialog.header"
      :obj-id="dialog.objId"
      :id-card="dialog.idCard"
      :visible.sync="dialog.open_expert_detail"
      v-if="dialog.open_expert_detail"
    ></expert-detail-dialog>
    <project-detail-dialog
      :tabDefaultValue="tabDefaultValue"
      :header="dialog.header"
      :objId="dialog.objId"
      :visible.sync="dialog.open_project_detail"
      v-if="dialog.open_project_detail"
    ></project-detail-dialog>
  </div>
</template>

<script>
import { DownloadIcon, ListIcon, AssignmentUserIcon, MailIcon } from 'tdesign-icons-vue';
import addEditGroup from './components/add-edit-group.vue';
import SelectProject from './components/select-project.vue';
import SelectExpert from './components/select-expert.vue';
import ProjectApproval from './components/project-approval.vue';
import AddEditReviewStandard from './components/add-edit-review-standard.vue';

import ExpertReviewList from './components/expert-review-list.vue';

import ExpertSmsTemplate from './components/expert-sms-template.vue';
import { getFilesByUserId } from '@/api/common';
import ExpertDetailDialog from '../../zjk/expert/components/expert-detail-dialog.vue';
import projectDetailDialog from '../project/components/project-detail-dialog.vue';
import filters from '@/filters/index';

export default {
  name: 'review-group',
  components: {
    addEditGroup,
    SelectExpert,
    SelectProject,
    DownloadIcon,
    ListIcon,
    AssignmentUserIcon,
    MailIcon,
    ExpertReviewList,
    ProjectApproval,
    AddEditReviewStandard,
    ExpertSmsTemplate,
    ExpertDetailDialog,
    projectDetailDialog,
  },
  dicts: ['project_type', 'prof_tit', 'duty', 'kjsf_review_type', 'education', 'degree', 'msg_template_type'],
  data() {
    return {
      tabDefaultValue: '1',
      actived: [],
      dataOptions: [],
      projectList: [],
      expertList: [],
      projectColumns: [
        { colKey: 'project.projectName', title: '项目名称', align: 'center', width: 220 },
        { colKey: 'project.adviceFunding', title: '投入经费', align: 'center', width: 100 },
        // {colKey: 'project.projectCategoryName', title: '计划类别', align: "center"},
        // {colKey: 'project.projectType', title: '项目类型', align: "center"},
        { colKey: 'project.projectLeader.name', title: '负责人', align: 'center' },
        { colKey: 'project.sysDept.deptName', title: '承担单位', align: 'center', width: 220 },
        { colKey: 'sumScore', title: '评审平均分', align: 'center' },
        { colKey: 'projectStatus', title: '是否通过', align: 'center', width: 120 },
        // {colKey: 'project.attributeDeptName', title: '归口单位',align: "center"},
        {
          colKey: 'op',
          title: '操作',
          align: 'center',
          width: 160,
        },
      ],
      projectColumns2: [
        { colKey: 'project.projectName', title: '项目名称', align: 'center', width: 180 },
        { colKey: 'project.adviceFunding', title: '投入经费', align: 'center', width: 100 },
        // {colKey: 'project.projectCategoryName', title: '计划类别', align: "center"},
        // {colKey: 'project.projectType', title: '项目类型', align: "center"},
        { colKey: 'project.projectLeader.name', title: '负责人', align: 'center', width: 100 },
        { colKey: 'project.sysDept.deptName', title: '承担单位', align: 'center', width: 180 },
        { colKey: 'projectStatus', title: '是否通过', align: 'center', width: 120 },
        // {colKey: 'project.attributeDeptName', title: '归口单位',align: "center"},
        {
          colKey: 'op',
          title: '操作',
          align: 'center',
          width: 160,
        },
      ],
      expertColumns: [
        { colKey: 'experts.sysUser.nickName', title: '专家姓名', align: 'center' },
        { colKey: 'experts.age', title: '年龄', align: 'center', width: 80 },
        { colKey: 'experts.sysUser.dept.deptName', title: '所在单位', align: 'center', width: 180 },
        { colKey: 'experts.sysUser.phonenumber', title: '手机号', align: 'center', width: 130 },
        { colKey: 'experts.sysUser.duty', title: '职务/职称', align: 'center' },
        // { colKey: 'experts.declareDeptName', title: '部门', },
        { colKey: 'experts.recommendMajorName', title: '组别', align: 'center', width: 120 },
        // {colKey: 'experts.sysUser.majorName', title: '专业',align: "center"},
        { colKey: 'experts.sysUser.majorNowName', title: '现从事专业', align: 'center' },
        { colKey: 'experts.sysUser.education', title: '学历/学位', align: 'center' },
        // {colKey: 'experts.sysUser.degree', title: '学位',align: "center"},
        { colKey: 'sendMsg', title: '短信通知/是否参加', align: 'center', width: 160 },
        // {colKey: 'experts.joinType', title: '是否参加',align: "center"},
        // {colKey: 'experts.joinReviewTimes', title: '参与评审次数',align: "center"},
        // {colKey: 'experts.joinProjectTimes', title: '参与项目次数',align: "center"},

        // {colKey: 'experts.phoneNumber', title: '联系方式',align: "center"},
        {
          colKey: 'op',
          title: '操作',
          width: 130,
          align: 'center',
        },
      ],
      visible: false,
      useActived: true,
      activeId: '',
      activeIds: [],
      TreeReviewTeamData: [],
      selectTreeTeamObj: {},
      dialog: {
        parentId: 0,
        objId: 0,
        teamId: 0,
        projectId: 0,
        editOpen: false,
        open_add_edit: false,
        header: '',
        open_detail: false,
        open_review_list: false,
        open_select_project: false,
        open_select_expert: false,
        open_project_approval: false,
        projectName: '',
        open_project_detail: false,
        open_review_standard: false,
        open_outline_detail: false,
        open_acceptance_detail: false,
        open_sms_template: false,
        open_expert_detail: false,
        formData: {},
        nickName: '',
        projectList: [],
        expertLeader: {},
        rowId: null,
        idCard: '',
      },
      requiredRules: {
        name: [{ required: true, message: '分组名不能为空' }],
      },
      formData: {
        id: '',
        reviewType: '',
        name: '', // 分组名
        note: '',
        subjectClassification: [],
        planName: '',
        reviewMeetingDate: '',
      },
      baseLoading: false,
      dataLoading: false,
      temList: [],
    };
  },
  watch: {
    'formData.id': {
      immediate: true,
      handler(val) {
        if (this.formData.id) {
          this.teamProjectGet();
          this.teamExpertGet();
        }
      },
    },
  },
  created() {
    this.dataLoading = true;
    this.getListReviewTeam();
    this.getIndexList();
  },
  methods: {
    openProjectDetail(row) {
      this.dialog.header = row.project.projectName;
      this.dialog.objId = row.project.id;
      this.dialog.editOpen = false;
      if (this.formData.reviewType === '1') {
        this.tabDefaultValue = '1';
      } else if (this.formData.reviewType === '2') {
        this.tabDefaultValue = '2';
      }
      // this.tabDefaultValue
      this.dialog.open_project_detail = true;
    },
    handleExportPDF(id) {
      const instance = this.$loading({
        fullscreen: true,
        attach: 'body',
        preventScrollThrough: false,
      });
      this.$api.kjsf.project
        .createZjBankPdfByWindows(id)
        .then((response) => {
          window.open(response.data.fullFilePath, '_blank');
          instance.hide();
        })
        .catch((e) => {
          instance.hide();
          this.$message.error(e.toString());
        });
    },
    openReviewDetail(row) {
      this.dialog.objId = row.project.id;
      this.dialog.teamId = this.formData.id;
      this.dialog.projectName = row.project.projectName;
      // 先判断有没有设置专家组长
      let expertLeader = null;
      const obj = this.expertList.find((val) => val.teamLeader === '1');
      if (obj) {
        expertLeader = {
          id: obj.experts.userId,
          nickName: obj.experts.sysUser.nickName,
        };
      }
      this.dialog.expertLeader = expertLeader;
      this.dialog.rowId = row.id;
      this.dialog.open_review_list = true;
    },
    getTeamExpertLeaderFile(row) {
      // 先判断有没有设置专家组长
      const obj = this.expertList.find((val) => val.teamLeader === '1');
      if (!obj) {
        this.$message.error('未设置专家组组长!');
        return false;
      }
      // 获取当前组长的评审意见表附件
      getFilesByUserId(row.id, obj.experts.sysUser.id)
        .then((res) => {
          const files = {};
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = [];
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath,
            });
          });
          const dgPsYjsFilesNow = files.dgPsYjs || [];
          if (dgPsYjsFilesNow.length > 0) {
            window.open(dgPsYjsFilesNow[0].url, '_blank');
          } else {
            this.$message.error(`${obj.experts.sysUser.nickName}-还未提交评审意见表`);
          }
        })
        .catch((e) => {
          this.$message.error(e.toString());
        });
    },
    handleExport(url, id, title) {
      this.$download(url, { teamId: id }, `${title}_${new Date().getTime()}.xls`);
    },
    getDuty(duty, profTit) {
      const newProfTit = filters.filterByDict(profTit, this.dict.type.prof_tit, null);
      return `${duty}/${newProfTit}`;
    },
    changeActived(id) {
      this.actived = [id];
      this.$api.kjsf.review
        .teamGet(id)
        .then((response) => {
          response.data.subjectClassification = response.data.subjectClassification
            ? response.data.subjectClassification.split(',').filter((item) => item !== '')
            : [];
          Object.assign(this.formData, response.data);
        })
        .catch((e) => {
          this.$message.error(e.toString());
        });
    },
    getIndexList() {
      return this.$api.kjsf.review
        .indexList(this.queryParams)
        .then((res) => {
          this.dataOptions = res.rows.map((val) => ({ label: val.name, value: val.id }));
        })
        .catch((e) => {
          this.$message.error(e.toString());
        });
    },
    removeNode(node) {
      this.$api.kjsf.review
        .teamDel(node.data.id)
        .then((res) => {
          this.getListReviewTeam();
          this.$message.success('删除成功');
        })
        .catch((e) => {
          this.$message.error(e.toString());
        });
    },
    // 获取树形
    getTreeReviewTeam() {
      this.$api.kjsf.review
        .teamTree()
        .then((res) => {
          this.dataLoading = false;
          // this.TreeReviewTeamData = res.data;
        })
        .catch((e) => {
          this.dataLoading = false;
          this.$message.error(e.toString());
        });
    },
    getListReviewTeam() {
      this.$api.kjsf.review
        .teamList()
        .then((res) => {
          this.dataLoading = false;
          this.TreeReviewTeamData = this.handleTree(res.data, 'id');
        })
        .catch((e) => {
          this.dataLoading = false;
          this.$message.error(e.toString());
        });
    },
    onTreeActive(value, context) {
      this.actived = [context.node.data.id];
      if (context.node.data.reviewMenuType === '2') {
        this.$api.kjsf.review
          .teamGet(context.node.data.id)
          .then((response) => {
            response.data.subjectClassification = response.data.subjectClassification
              ? response.data.subjectClassification.split(',').filter((item) => item !== '')
              : [];
            Object.assign(this.formData, response.data);
          })
          .catch((e) => {
            this.$message.error(e.toString());
          });
      } else {
        this.formData.id = null;
      }
    },
    // 本组申报项目列表
    teamProjectGet() {
      this.$api.kjsf.review
        .teamProjectGet(this.formData.id)
        .then((response) => {
          this.projectList = response.data;
        })
        .catch((e) => {
          this.$message.error(e.toString());
        });
    },
    // 查专家列表
    teamExpertGet() {
      this.$api.kjsf.review
        .teamExpertGet(this.formData.id)
        .then((response) => {
          this.expertList = response.data;
        })
        .catch((e) => {
          this.$message.error(e.toString());
        });
    },
    selectProject() {
      if (!this.formData.id) {
        return this.$message.error('请选择分组');
      }
      this.dialog.projectList = this.projectList;
      this.dialog.open_select_project = true;
    },
    selectExpert() {
      if (!this.formData.id) {
        return this.$message.error('请选择分组');
      }
      this.dialog.open_select_expert = true;
    },
    // 删除项目
    teamProjectDel(id) {
      const confirmDia = this.$dialog.confirm({
        header: '系统提示',
        body: `是否确认删除？`,
        theme: 'warning',
        onConfirm: ({ e }) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          });
          this.$api.kjsf.review
            .teamProjectDel(id)
            .then((res) => {
              this.$message.success('删除成功');
              this.teamProjectGet();
              confirmDia.destroy();
            })
            .catch((e) => {
              confirmDia.update({
                confirmBtn: {
                  loading: false,
                },
              });
              this.$message.error(e.toString());
            });
        },
      });
    },

    setTeamExpertLeader(row) {
      const confirmDia = this.$dialog.confirm({
        header: '系统提示',
        body: `是否设置"${row.experts.sysUser.nickName}"为本组专家评审组长?`,
        theme: 'warning',
        onConfirm: ({ e }) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          });
          this.$api.kjsf.review
            .setTeamLeader({
              teamId: row.teamId,
              expertsId: row.experts.id,
            })
            .then((res) => {
              this.$message.success('设置成功');
              this.teamExpertGet();
              confirmDia.destroy();
            })
            .catch((e) => {
              confirmDia.update({
                confirmBtn: {
                  loading: false,
                },
              });
              this.$message.error(e.toString());
            });
        },
      });
    },
    // 删除专家
    teamExpertDel(id) {
      const confirmDia = this.$dialog.confirm({
        header: '系统提示',
        body: `是否确认删除？`,
        theme: 'warning',
        onConfirm: ({ e }) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          });
          this.$api.kjsf.review
            .teamExpertDel(id)
            .then((res) => {
              this.$message.success('删除成功');
              this.teamExpertGet();
              confirmDia.destroy();
            })
            .catch((e) => {
              confirmDia.update({
                confirmBtn: {
                  loading: false,
                },
              });
              this.$message.error(e.toString());
            });
        },
      });
    },
  },
};
</script>

<style scoped lang="less">
@import url('@/style/duty.less');
</style>
